package com.ecourseapp;

import android.app.Application;

import com.brentvatne.react.ReactVideoPackage;
import com.ecourseapp.NativeForRN.Alipay.AlipayPackage;
import com.ecourseapp.NativeForRN.BaseBridgeReactPackage;
import com.ecourseapp.NativeForRN.NewMainReactPackage;
import com.ecourseapp.NativeForRN.wechat.WxpayPackage;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.modules.network.ReactCookieJarContainer;
import com.facebook.soloader.SoLoader;
import com.github.yamill.orientation.OrientationPackage;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.interceptor.HttpLoggingInterceptor;
import com.reactlibrary.RNReactNativeDocViewerPackage;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;

import okhttp3.OkHttpClient;

public class MainApplication extends Application implements ReactApplication {

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
            return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                    new NewMainReactPackage(),
                    new BaseBridgeReactPackage(),
                    new AlipayPackage(),
                    new WxpayPackage(),
                    new OrientationPackage(),
                    new ReactVideoPackage(),
                    new RNReactNativeDocViewerPackage()
            );
        }
    };

    public static OkHttpClient okHttpClient = null;

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor("okGo");
        httpLoggingInterceptor.setColorLevel(Level.INFO);
        httpLoggingInterceptor.setPrintLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);
        builder.addInterceptor(httpLoggingInterceptor);
        //全局的读取超时时间
        builder.readTimeout(60_000, TimeUnit.MILLISECONDS);
        //全局的写入超时时间
        builder.writeTimeout(60_000, TimeUnit.MILLISECONDS);
        //全局的连接超时时间
        builder.connectTimeout(60_000, TimeUnit.MILLISECONDS);
        builder.cookieJar(new ReactCookieJarContainer());
        okHttpClient = builder.build();
        SoLoader.init(this, /* native exopackage */ false);
        OkGo.getInstance()
                .init(this)
                .setOkHttpClient(okHttpClient)
                .setRetryCount(3);
    }


}
